package model

import (
	"github.com/Shopify/sarama"
	"github.com/spf13/viper"
	"log"
)

var MQ sarama.SyncProducer

func KafkaMQ() {
	conf := sarama.NewConfig()
	conf.Producer.RequiredAcks = sarama.WaitForAll //需要leader和follow都确认
	conf.Producer.Partitioner = sarama.NewRandomPartitioner
	conf.Producer.Return.Successes = true

	cli, err := sarama.NewSyncProducer([]string{viper.GetString("kafka.adder")}, conf)
	if err != nil {
		log.Fatalln(err)
	}
	MQ = cli
}
